﻿using System.Diagnostics;
using System.Globalization;

namespace PrimeNumber
{
    internal class Program
    {

        static void Main(string[] args)
        {
            //输入想求最大质数的范围
            Console.WriteLine("请输入一个较大的数");
            int num = Convert.ToInt32(Console.ReadLine());
            int max = 2;
            //计算程序运行时间
            Stopwatch sw = new Stopwatch();
            sw.Start();
          
            //遍历质数
            for (int i = 3; i <= num; i += 2)
            {               
                bool prime = true;
                for (int j = 3; j <= i / 2; j += 2)
                {
                    if (i % j == 0)
                    {
                        prime = false;
                        break;
                    }                   
                }
                if(prime)
                {
                    if (i > max)
                    {
                        max = i;
                    }
                }
            }
            sw.Stop();
            TimeSpan ts = sw.Elapsed;
            Console.WriteLine($"最大质数为{max},所用时间为{ts.TotalSeconds}");
        }
    }
}